function dai(a) {
	var aa = a.value;
	var ss = /^[a-zA-Z1-9]+[a-zA-Z0-9]*$/;
	var nn = a.parentNode.getElementsByTagName("span")[0];
	if (!(ss.test(aa)) && aa != "") {
		nn.innerHTML = "输入格式不正确";
	} else {
		nn.innerHTML = "";
	}
}
function jiao(a) {
	var aa = a.value;
	var ss = /^[1-9]\d*$/;
	var nn = a.parentNode.getElementsByTagName("span")[0];
	if (!(ss.test(aa)) && aa != "") {
		nn.innerHTML = "请输入数字";
	} else {
		nn.innerHTML = "";
	}
}
function telephone(a) { 
	var aa = a.value;
	var ss = /^(?:13\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/;
	var nn = a.parentNode.getElementsByTagName("span")[0];
	if (!(ss.test(aa)) && aa != "") {
		nn.innerHTML = "格式不正确";
	} else {
		nn.innerHTML = "";
	}
}
function phone(a) {
	var aa = a.value;
	var ss = /^(((\d{3,6}-)\d{6,8}(-\d{3,5})?)|(\d{8})?)$/;
	var nn = a.parentNode.getElementsByTagName("span")[0];
	if (!(ss.test(aa)) && aa != "") {
		nn.innerHTML = "格式不正确";
	} else {
		nn.innerHTML = "";
	}
}

function checkdd(bb) {
	var ss = document.getElementsByName("checkbox");
	var sb = document.getElementById("bu");
	var ee = 0;
	if (bb.checked == true) {
		bb.checked = true;
	} else if (bb.checked == false) {
		bb.checked = false;
	}
	for ( var i = 0; i < ss.length; i++) {
		if (ss[i].checked == true) {
			ee = 1;
			break;
		}
	}
	if (ee == 0) {
		sb.disabled = true;
	} else {
		sb.disabled = false;
	}
}

function che(a) {
	var ss = document.getElementsByName("checkbox");
	var sb = document.getElementById("bu");
	if (a.checked == true) {
		for ( var i = 0; i < ss.length; i++) {
			ss[i].checked = true;
			sb.disabled = false;
		}
	} else {
		for ( var i = 0; i < ss.length; i++) {
			ss[i].checked = false;
			sb.disabled = true;
		}
	}

}
function count() {
	var ta = document.getElementById("PLList");
	var allcash = document.getElementById("allcash");
	for (i = 1; i < ta.rows.length; i++) {
		var s = ta.rows[i].childNodes[3].childNodes[0].value;
		var ss = ta.rows[i].childNodes[5].childNodes[0].value;
		ta.rows[i].childNodes[6].childNodes[0].value = s * ss;
		allcash.value = allcash.value * 1 + s * ss;
	}
	allCount = ta.rows.length;
}
function overload(a, b) {
	b.value = a.value;
}
function allover() {
	document.getElementById("orderindexConsignee").value = document
			.getElementById("n2").value;
	document.getElementById("orderindexAddress").value = document
			.getElementById("a2").value;
	document.getElementById("orderindexPostcode").value = document
			.getElementById("p2").value;
	document.getElementById("orderindexMobilephone").value = document
			.getElementById("ph2").value;
	document.getElementById("orderindexPhone").value = document
			.getElementById("h2").value;
	document.getElementById("orderindexEmail").value = document
			.getElementById("e2").value;
}
function overn() {
	document.getElementById("orderindexConsignee").value = document
			.getElementById("n2").value;
}
function overa() {
	document.getElementById("orderindexAddress").value = document
			.getElementById("a2").value;
}
function overp() {
	document.getElementById("orderindexPostcode").value = document
			.getElementById("p2").value;
}
function overph() {
	document.getElementById("orderindexMobilephone").value = document
			.getElementById("ph2").value;
}
function overh() {
	document.getElementById("orderindexPhone").value = document
			.getElementById("h2").value;
}
function overe() {
	document.getElementById("orderindexEmail").value = document
			.getElementById("e2").value;
}

function show(url) {
	document.forms[1].method = "post";
	document.forms[1].target = "ppp";
	document.forms[1].action = url;
	document.forms[1].submit();
}
function addPro(id, vip, name, address, postcode, phone, city, point, cash,
		province, town, cityId,username,mobile,email) {

	// newOpenerCitySelect1(town);
	window.opener.document.getElementById("id").value = id;
	window.opener.document.getElementById("v2").value = vip;
	window.opener.document.getElementById("n2").value = name;
	window.opener.document.getElementById("a2").value = address;
	window.opener.document.getElementById("p2").value = postcode;
	window.opener.document.getElementById("ph2").value = mobile;
	window.opener.document.getElementById("h2").value = phone;
	window.opener.document.getElementById("e2").value = email;
	window.opener.document.getElementById("paypoint").value = point;
	window.opener.document.getElementById("c1").value = cityId;
	window.opener.document.getElementById("u2").value = username;
	// window.opener.getElementById("hidecash").value = city;
	window.opener.document.getElementById("paycash").value = cash;

	window.close();
	window.opener.alert("\u6dfb\u52a0\u6210\u529f!!");
}

function addProduct(id,name){ 
	window.opener.document.getElementById("ecoupon.productid").value = id;
	window.opener.document.getElementById("product").value = name;
	window.close();
	window.opener.alert("\u6dfb\u52a0\u6210\u529f!!");
}

function mouseOver() {
	event.srcElement.className = "delMouseOver";
}
function mouseOut() {
	event.srcElement.className = "scheduleButtonVisible";
}
function mouseOver1() {
	window.opener.event.srcElement.className = "delMouseOver";
}
function mouseOut1() {
	window.opener.event.srcElement.className = "scheduleButtonVisible";
}
function newHospitalVisit() {
	allCount = window.orderForm.temp.value;
	var pll = document.getElementById("PLList");
	newRow = pll.insertRow(pll.rows.length);
	newRow.id = "tdt";
	newRow.ln = allCount;
	newRow.bgColor = "#e0e0e0";
	newRow.className = "tableData";
	c1 = newRow.insertCell(0);
	c1.id = "delItem";
	c1.ln = allCount;
	c1.className = "scheduleButtonVisible";
	c1.onclick = delIt;
	c1.onmouseover = mouseOver;
	c1.onmouseout = mouseOut;
	c1.innerHTML = "删除<input type=hidden name=deid" + allCount
			+ " value=0><input type=hidden name=ownid" + allCount
			+ " value=0><input type='hidden' name='edit' value=0>";

	c2 = newRow.insertCell(1);
	c2.ln = allCount;
	c2.innerHTML = "<input type=checkbox name=select value="
			+ allCount
			+ " style='display:none;' checked><input type=text size=55 maxlength=60 name=name"
			+ allCount + " ln=" + allCount
			+ " class=tableData onkeyup='modifiedIt()'>";
	c3 = newRow.insertCell(2);
	c3.ln = allCount;
	c3.innerHTML = "<input type=text size=10  name=comm" + allCount + " ln="
			+ allCount + " maxlength=255/>";
	c4 = newRow.insertCell(3);
	c4.ln = allCount;
	c4.innerHTML = "<input type=text size=10 value=0 maxlength=100 name=price"
			+ allCount + " id=price" + allCount + " ln=" + allCount
			+ " class=tableData onkeyup='modifiedIt()'  onBlur='reCash232("
			+ allCount + ")' onchange='return checkPrice(this)'>";

	c5 = newRow.insertCell(4);
	c5.ln = allCount;
	c5.innerHTML = "<input type=hidden name=tagimp"
			+ allCount
			+ " value=999><select size=1 maxlength=100 name=isNeedInvoice"
			+ allCount
			+ " ln="
			+ allCount
			+ " class=tableData ><option value=0>否</option><option value=99>是</option></select>";

	c6 = newRow.insertCell(5);
	c6.ln = allCount;
	c6.innerHTML = "<input type=text size=10 maxlength=100 name=count"
			+ allCount + " ln=" + allCount
			+ " class=tableData onkeyup='modifiedIt()' onBlur='reCash232("
			+ allCount + ")' value=1 onchange='return checkCount(this)'>";

	c7 = newRow.insertCell(6);
	c7.ln = allCount;
	c7.innerHTML = "<input type=text size=10 maxlength=100 name=cash"
			+ allCount + " ln=" + allCount
			+ " class=tableData  value=0 onkeyup='modifiedIt()' readOnly>";

	allCount++;
	window.orderForm.temp.value = allCount;
}
function delIt() {
	var pll = document.getElementById("PLList");
	line = parseInt(event.srcElement.ln, 10);
	if (line > 0) {
		for (i = 1; i < pll.rows.length; i++) {
			if (tdt[i].ln == line) {
				if (!confirm("\u786e\u5b9a\u5220\u9664\u5417?")) {
					return;
				} 
				 
				pll.deleteRow(i); 
				//allCount--;      
				for (z = 1; z < pll.rows.length; z++) {
					var tagfd = pll.rows[z].childNodes[4].childNodes[3].value;	 
					if(tagfd == 1){
						document.getElementById("delivercash").value = 0; 
					} else{
						document.getElementById("delivercash").value = document.getElementById("tagdeliver").value;
					}
				}
				
				if(pll.rows.length==1){
					document.getElementById("delivercash").value = document.getElementById("tagdeliver").value;
				}
			}
		} 
	}
	
	var  price =  document.getElementById("ecouponPrice").value;
	if(price!="" && price!="0" ){
		document.getElementById("ecouponPrice").value = "";
		alert("商品以变更,请重新点击使用优惠卷");
	}
	reCash3();
}
function reCash(value) {

	document.orderForm.delivercash.value = value;
	reCash3();
}
function reCash2(v3) {
	var cc1 = eval("window.orderForm.cash" + v3);
	var cc2 = eval("window.orderForm.count" + v3);
	var cc3 = eval("window.orderForm.price" + v3);
	var cc4 = eval("window.orderForm.isNeedInvoice" + v3);
	var cc5 = eval("window.orderForm.tagprice" + v3);
	var cc6 = eval("window.orderForm.tagimp" + v3);

	if (cc6.value * 1 != 999) {
		if (cc4.value * 1 == 0) {
			cc3.value = cc5.value;
		} else {
			cc3.value = cc4.value;
		}
	}

	cc1.value = cc2.value * cc3.value;

	reCash3();
}

function reCash232(v3) {
	var cc1 = eval("window.orderForm.cash" + v3);
	var cc2 = eval("window.orderForm.count" + v3);
	var cc3 = eval("window.orderForm.price" + v3);
	cc1.value = cc2.value * cc3.value;

	reCash3();
}

function reCash3() {

	var ta = document.getElementById("PLList");
	var tal = 0;
	for (i = 1; i < ta.rows.length; i++) {
		tal = ta.rows[i].childNodes[6].childNodes[0].value * 1 + tal;
	}
	var c = window.orderForm.delivercash.value * 1;
	var p = window.orderForm.paypoint1.value * 1;
	var pc = window.orderForm.paycash1.value * 1;

	if (!tal == 0) {

		if (p > window.orderForm.paypoint.value || p < 0) {
			alert("请输入合理积分");
			return false;
		}

		if (pc > window.orderForm.paycash.value || pc < 0) {
			alert("请输入合理滞留金");
			return false;
		}
		if (pc + p > tal) {
			alert("滞留金与积分的总和不得大于总金额");
			return false;
		}
	}
	
	var ecouponPrice = document.getElementById("ecouponPrice").value*1;
 	if(ecouponPrice!=""){
		window.orderForm.allcash.value = tal + c - p - pc - ecouponPrice;
	}else{
		window.orderForm.allcash.value = tal + c - p - pc
	}
}
function modifiedIt(field) {
	var pll = document.getElementById("PLList");
	// field.value=checkText(field.value);
	modified = 1;
	line = parseInt(event.srcElement.ln, 10);
	if (line > 0) {
		for (i = 1; i < pll.rows.length; i++) {
			if (tdt[i].ln == line) {
				document.orderForm.edit[i].value = 1;
			}
		}
	}
}
function delAll() {
	var pll = document.getElementById("PLList");
	if (pll.rows.length > 1) {
		if (!confirm("\u786e\u5b9a\u5168\u90e8\u5220\u9664\u5417?")) {
			return;
		}
		for (i = pll.rows.length; i > 1; i--) {
			pll.deleteRow(i - 1);
		}
		// allCount--
	}
	document.getElementById("delivercash").value = document.getElementById("tagdeliver").value;   
	
	
	var  price =  document.getElementById("ecouponPrice").value;
	if(price!="" && price!="0" ){
		document.getElementById("ecouponPrice").value = "";
		alert("商品以变更,请重新点击使用优惠卷");
	}
	
	reCash3();
	tableFont("12px");
}
function tableFont(aa) {
	var ss = document.getElementsByTagName("table");
	for (i = 0; i < ss.length; i++) {
		ss[i].style.fontSize = aa;
	}
}

function newOpenerHistory(a, b, c, d, province, city, town, id,phone,email) {
	if (province != null && province != "" && city != null && city != ""
			&& town != null && town != "") {
		var provinceOptions = window.opener.document
				.getElementById("provinces");
		var itemCount1 = provinceOptions.options.length;
		for ( var i = 0; i < itemCount1; i++) {
			if (provinceOptions.options[i].value == province) {
				provinceOptions.options[i].selected = true;
			}
		}
		window.opener.document.getElementById("provinces").onchange();

		var cityOptions = window.opener.document.getElementById("citys");
		var itemCount = cityOptions.options.length;
		for ( var i = 0; i < itemCount; i++) {
			if (cityOptions.options[i].value == city) {
				cityOptions.options[i].selected = true;
			}
		}

		window.opener.document.getElementById("citys").onchange();

		var villageOptions = window.opener.document.getElementById("villages");
		var itemCount2 = villageOptions.options.length;
		for ( var i = 0; i < itemCount2; i++) {
			if (villageOptions.options[i].value == town) {
				villageOptions.options[i].selected = true;
			}
		}
		window.opener.document.getElementById("villages").onchange();
	}
	window.opener.document.getElementById("orderindexConsignee").value = a;
	window.opener.document.getElementById("orderindexAddress").value = b;
	window.opener.document.getElementById("orderindexPostcode").value = c;
	window.opener.document.getElementById("orderindexMobilephone").value = d;
	window.opener.document.getElementById("orderindexPhone").value = phone;
	window.opener.document.getElementById("orderindexEmail").value = email;
	window.opener.document.getElementById("historyId").value = id;
	window.close();
	window.opener.alert("\u6dfb\u52a0\u6210\u529f!!");
}

function newOpenerHospitalVisit(a, b, c, invoice, d,f) {
	allCount = window.opener.orderForm.temp.value;
	for (i = 1; i <= allCount; i++) {
		var cc = eval("window.opener.orderForm.deid" + i);
		if (cc == null) {
			continue;
		}
		if (c == cc.value) {
			alert("此记录已经存在");
			return;
		}
	}

	var pll = window.opener.document.getElementById("PLList");
	newRow = pll.insertRow(pll.rows.length);
	newRow.id = "tdt";
	newRow.ln = allCount;
	newRow.bgColor = "#e0e0e0";
	newRow.className = "tableData";
	c1 = newRow.insertCell(0);
	c1.id = "delItem";
	c1.ln = allCount;
	c1.className = "scheduleButtonVisible";
	c1.onclick = opener.delIt;
	c1.onmouseover = opener.mouseOver;
	c1.onmouseout = opener.mouseOut;
	c1.innerHTML = "删除<input type=hidden name=deid" + allCount + " value=" + c
			+ "><input type=hidden name=ownid" + allCount + " value=" + a
			+ "><input type='hidden' name='edit' value=" + a + ">";
	c2 = newRow.insertCell(1);
	c2.ln = allCount;
	c2.innerHTML = b;
	c3 = newRow.insertCell(2);
	c3.ln = allCount;
	c3.innerHTML = "<input type=text size=10 maxlength=255 name=comm"
			+ allCount + " ln=" + allCount + " />";
	c4 = newRow.insertCell(3);
	c4.ln = allCount;
	c4.innerHTML = "<input type=text size=10 value=" + a
			+ " maxlength=100 name=price" + allCount + " id=price" + allCount
			+ " ln=" + allCount
			+ " class=tableData onkeyup='modifiedIt()'  onBlur='reCash232("
			+ allCount + ")' onchange='return checkPrice(this)'>"
			+ "<font color=ff0000 size='2'>" + d + "</front>";

	c5 = newRow.insertCell(4);
	c5.ln = allCount;
	c5.innerHTML = "<input type=hidden name=tagimp" + allCount + " value=888><input type=hidden name=tagprice" + allCount
			+ " value=" + a
			+ "><select size=1 maxlength=100 name=isNeedInvoice" + allCount
			+ " ln=" + allCount
			+ " class=tableData onkeyup='modifiedIt()' onchange='reCash2("
			+ allCount + ")'><option value=0>否</option><option value="
			+ invoice + ">是</option></select><input type=hidden id=tagfd" + allCount
			+ " value="+f+">";

	c6 = newRow.insertCell(5);
	c6.ln = allCount;
	c6.innerHTML = "<input type=text size=10 maxlength=100 name=count"
			+ allCount + " ln=" + allCount
			+ " class=tableData onkeyup='modifiedIt()' onBlur='reCash232("
			+ allCount + ")' value=1 onchange='return checkCount(this)'>";

	c7 = newRow.insertCell(6);
	c7.ln = allCount;
	c7.innerHTML = "<input type=text size=10 maxlength=100 name=cash"
			+ allCount + " ln=" + allCount + " value=" + a
			+ " class=tableData onkeyup='modifiedIt()' readOnly>"; 
	if(f == 1){
		window.opener.document.getElementById("delivercash").value = 0; 	
	}
	
	allCount++;
	window.opener.orderForm.temp.value = allCount;
	var ta = window.opener.document.getElementById("PLList");
	var tal = 0;
	for (i = 1; i < ta.rows.length; i++) {
		tal = ta.rows[i].childNodes[6].childNodes[0].value * 1 + tal;
	}

	var c = window.opener.orderForm.delivercash.value * 1;
	var p = window.opener.orderForm.paypoint.value * 1;
	var pc = window.opener.orderForm.paycash.value * 1;
	//window.opener.orderForm.allcash.value = tal + c - p - pc;
	window.opener.orderForm.allcash.value = tal + c;
}

function newOpenerHistoryInsert(a, b, c, d, userid) {

	newOpenerHistory(a, b, c, d, "", "", "", "");
}

function theBigPropper(url, w, h) {
	var l = (screen.availWidth - w) / 2;
	var t = (screen.availHeight - h) / 2
	var s = 'width=' + w + ', height=' + h + ', top=' + t + ', left=' + l;
	var src = s + ",location=no,menubar=no,resizable=yes,status=no,toolbar=no";
	newWin = window.open(url, "theNewWindow", src);
	tableFont("12px");
}
function tiao(uri) {
	if (uri == jsCtx+"/addBillManage.do?method=downloadExcel") {
		var form1 = document.getElementById("for");
		form1.action = uri;
		form1.submit();
		form1.action = jsCtx+"/addBillManage.do?method=resultList";
	} else {
		var ss = window.location;
		ss.href = uri;
		tableFont("12px");
	}
}
function tiaosubmit(uri) {
	var form1 = document.getElementById("form1");
	form1.action = uri;
	form1.submit();
}
function yin(aa) {
	var s = document.getElementById(aa);
	if (s.style.display == 'block') {
		s.style.display = 'none';
	} else {
		s.style.display = 'block';
		tableFont("12px");
	}
}
function xuan(s) {
	var aa = document.getElementById("xuanze");
	var chang = document.getElementById("chang1");
	var ww = aa.getElementsByTagName("select");
	for ( var i = 0; i < ww.length; i++) {
		if (s.name != ww[i].name) {
			ww[i].options[0].selected = true;
		} else {
			if (ww[i].options[0].selected == true) {
				chang.disabled = true;
			} else {
				chang.disabled = false;
			}
		}
	}
}
function countAll() {
	var ss = document.getElementById("buzhi");
	var a = document.getElementById("gaousepoint");
	var b = document.getElementById("gaousebalance");
	var c = document.getElementById("gaoneedcarriage");
	var d = document.getElementById("gaotaltole");
	var total = 0;
	var se = ss.rows.length - 4;
	for ( var i = 2; i < se; i++) {
		var s1 = ss.rows[i].childNodes[2].innerHTML;
		var s2 = ss.rows[i].childNodes[3].innerHTML;
		ss.rows[i].childNodes[6].innerHTML = s1 * s2;
		total = total + ss.rows[i].childNodes[6].innerHTML * 1;
	}
	d.innerHTML = total * 1 + c.innerHTML * 1 - a.innerHTML * 1 - b.innerHTML
			* 1;
	tableFont("12px");
}
function setuid(uid, hr) {
	if (uid == null || uid == "") {
		alert("请先选择会员");
		return false;
	} else {
		hr.href = "customerManage.do?method=serachforHistoryByCondition&uid="
				+ uid;
		return true;
	}

}

function checkCount(thiss) {
	var aa = thiss.value;
	var ss = /^[0-9]*[1-9][0-9]*$/;
	if (!(ss.test(aa)) || aa == "") {
		alert("数量必须大于0的正整数");
		return false;
	}
}

function checkPrice(thiss) {
	var aa = thiss.value;
	var ss = /^\d{1,10}$|^\d{1,10}\.\d{1,1}\w?$/;
	if (!(ss.test(aa)) || aa == "" || aa < 0) {
		alert("请输入合理的价格");
		return false;
	}
} 